﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JOthello.Forms;
using Common.Model;
using Common.Extensions;
using System.Drawing;

namespace JOthello.Controls
{
    public class WantsToPlayControl
    {
        WantsToPlayForm WantsToPlayForm;


        public WantsToPlayControl(WantsToPlayForm form, CSpieler gegner)
        {
            this.WantsToPlayForm = form;

            WantsToPlayForm.PbxSpielerBild.Image = resizeForPictureBox(gegner.Bild);
            WantsToPlayForm.LblHerausforderung.Text = gegner.Name + " fordert dich heraus.";
            WantsToPlayForm.BtnAccept.Click += new EventHandler(BtnAccept_Click);
            WantsToPlayForm.BtnDecline.Click += new EventHandler(BtnDecline_Click);
        }

        #region events
        private void BtnDecline_Click(object sender, EventArgs e)
        {
            WantsToPlayForm.DialogResult = System.Windows.Forms.DialogResult.No;
            WantsToPlayForm.Close();
        }

        private void BtnAccept_Click(object sender, EventArgs e)
        {
            WantsToPlayForm.DialogResult = System.Windows.Forms.DialogResult.Yes;
            WantsToPlayForm.Close();
        }
        #endregion

        private Bitmap resizeForPictureBox(Bitmap bmp)
        {
            if (bmp == null) return null;
            return bmp.Resize((int)(((double)bmp.Width) / ((double)bmp.Height) * WantsToPlayForm.PbxSpielerBild.Height), WantsToPlayForm.PbxSpielerBild.Height);
        }
    }
}
